/**
 * @Time    : 2022/03/09 15:19
 * @Author  : WanRongJia
 * @License : Software business license
 * @Site    : www.linshensjl.top
 * @File    : list.js
 * @Software: Rich Web Platform
 * @Function: 查询菜单
 * @Version : 1.0
 **/
const { matchedData } = require("express-validator");
const { findMenuList } = require("./helpers/findMenuList");
const { buildTreeData } = require("../../../utils/buildTreeData");
const { buildResponse } = require("../../../utils/buildResponse");
const list = async function (req, res) {
	try {
		req = matchedData(req);
		let menuInfo = await findMenuList(req);
		menuInfo = await buildTreeData(menuInfo, "id", "pid");
		res.json(buildResponse(menuInfo, "查询成功", true));
	} catch (e) {
		res.json(e);
	}
};

module.exports = { list };
